package com.newjiabo.web.controller.ski;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;

import com.newjiabo.common.annotation.RepeatSubmit;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.newjiabo.common.annotation.Log;
import com.newjiabo.common.core.controller.BaseController;
import com.newjiabo.common.core.domain.AjaxResult;
import com.newjiabo.common.enums.BusinessType;
import com.newjiabo.ski.domain.SkiAfterSale;
import com.newjiabo.ski.service.ISkiAfterSaleService;
import com.newjiabo.common.utils.poi.ExcelUtil;
import com.newjiabo.common.core.page.TableDataInfo;

/**
 * 售后Controller
 *
 * @author CaoMengHui
 * @date 2023-09-23
 */
@Api(tags = "后台;售后控制器")
@RestController
@RequestMapping("/system/afterSale")
public class SkiAfterSaleController extends BaseController {

    @Autowired
    private ISkiAfterSaleService skiAfterSaleService;

    /**
     * 查询售后列表
     */
    @ApiOperation(value = "查询售后列表")
    @PreAuthorize("@ss.hasPermi('ski:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkiAfterSale skiAfterSale) {
        startPage();
        List<SkiAfterSale> list = skiAfterSaleService.selectSkiAfterSaleList(skiAfterSale);
        return getDataTable(list);
    }

    /**
     * 导出售后列表
     */
    @ApiOperation(value = "导出售后列表")
    @PreAuthorize("@ss.hasPermi('ski:sale:export')")
    @Log(title = "导出售后列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkiAfterSale skiAfterSale) {
        List<SkiAfterSale> list = skiAfterSaleService.selectSkiAfterSaleList(skiAfterSale);
        ExcelUtil<SkiAfterSale> util = new ExcelUtil<SkiAfterSale>(SkiAfterSale.class);
        util.exportExcel(response, list, "售后数据");
    }

    /**
     * 获取售后详细信息
     */
    @ApiOperation(value = "获取售后详细信息")
    @PreAuthorize("@ss.hasPermi('ski:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(skiAfterSaleService.getInfo(id));
    }

    /**
     * 新增售后
     */
    @ApiOperation(value = "新增售后")
    @PreAuthorize("@ss.hasPermi('ski:sale:add')")
    @Log(title = "新增售后", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody SkiAfterSale skiAfterSale) {
        return toAjax(skiAfterSaleService.insertSkiAfterSale(skiAfterSale));
    }

    /**
     * 修改售后
     */
    @RepeatSubmit
    @ApiOperation(value = "修改售后")
    @PreAuthorize("@ss.hasPermi('ski:sale:edit')")
    @Log(title = "修改售后", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkiAfterSale skiAfterSale) {
        return toAjax(skiAfterSaleService.updateSkiAfterSale(skiAfterSale));
    }

    /**
     * 删除售后
     */
    @ApiOperation(value = "删除售后")
    @PreAuthorize("@ss.hasPermi('ski:sale:remove')")
    @Log(title = "删除售后", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(skiAfterSaleService.deleteSkiAfterSaleByIds(ids));
    }

    @ApiOperation(value = "处理售后信息")
    @PostMapping(value = "/processAfter/{afterSaleId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "afterSaleId", value = "售后订单id", required = true, dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "actualRefundPrice", value = "实际退款金额", required = true, dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "auditRemark", value = "商家备注", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "serviceStatus", value = "售后状态", required = true, dataType = "String", paramType = "query", allowableValues = "refuseRefund,agreeRefund"),

    })
    public AjaxResult processAfter(@NotNull(message = "售后订单id不能为空") @PathVariable String afterSaleId,
                                   @RequestParam(required = false) Double actualRefundPrice,
                                   @NotNull(message = "商家备注不能为空") @RequestParam String auditRemark,
                                   @NotNull(message = "售后状态不能为空") @RequestParam String serviceStatus) {
        return toAjax(skiAfterSaleService.processAfter(afterSaleId, actualRefundPrice, auditRemark, serviceStatus));
    }
}
